package com.sxj.corejava.code08_常用类.日期类;

import com.sxj.corejava.constant.DateConstant;
import com.sxj.corejava.util.DateUtil;

import java.text.ParseException;
import java.util.Date;

/**
 * @author 石小俊
 * 2024年07月23日 8:59
 */
public class Test04_日期工具类 {
    public static void main(String[] args) throws ParseException {
        Date date = new Date();
        System.out.println(DateUtil.toString(date));
        System.out.println(DateUtil.toString(date,"yyyy-MM-dd HH:mm:ss"));
        System.out.println(DateUtil.toDate("2024年07月23日 08:59:52"));
        System.out.println(DateUtil.toDate("2024-07-23 08:59:52","yyyy-MM-dd HH:mm:ss"));
        System.out.println(DateUtil.toString(DateUtil.getYesterday(date)));
        System.out.println(DateUtil.toString(DateUtil.getTomorrow(date)));
        Date date2 = DateUtil.toDate("2024年07月25日 08:59:52");
        System.out.println(DateUtil.getDuringDay(date,date2));
        System.out.println(DateUtil.getDuringDay2(date,date2));
        System.out.println("年份:"+DateUtil.get(date, DateConstant.YEAR));
        System.out.println("月份:"+DateUtil.get(date, DateConstant.MONTH));
        System.out.println("天数:"+DateUtil.get(date, DateConstant.DATE));
        System.out.println("小时数:"+DateUtil.get(date, DateConstant.HOURS));
        System.out.println("分钟数:"+DateUtil.get(date, DateConstant.MINUTE));
        System.out.println("秒数:"+DateUtil.get(date, DateConstant.SECOND));
    }
}
